description "Prometheus"
start on runlevel [2345]
stop on runlevel [06]

env PROMETHEUS={{ prometheus_bin_path }}/prometheus
env USER={{ prometheus_user }}
env GROUP={{ prometheus_group }}
env DEFAULTS=/etc/default/prometheus
env RUNDIR=/var/run/prometheus
env PID_FILE=/var/run/prometheus/prometheus.pid

pre-start script
  [ -e $DEFAULTS ] && . $DEFAULTS

  mkdir -p $RUNDIR           || true
  chmod 0750 $RUNDIR         || true
  chown $USER:$GROUP $RUNDIR || true
end script

script
    # read settings from "/etc/default/prometheus", if available.
    [ -e $DEFAULTS ] && . $DEFAULTS

    exec start-stop-daemon -c $USER -g $GROUP -p $PID_FILE -x $PROMETHEUS -S -- \
      --config.file {{ prometheus_config_path }}/{{ prometheus_config_file }} \
      --web.listen-address {{ prometheus_listen_address }} \
      {% if prometheus_release_tag == 'latest' or prometheus_release_tag | regex_replace('^v(.*)$', '\\1') is version_compare('2.0.0', '>=') -%}
      --storage.tsdb.path {{ prometheus_tsdb_path }} \
      --storage.tsdb.retention {{ prometheus_tsdb_retention }} \
      {% else -%}
      --storage.local.path {{ prometheus_tsdb_path }} \
      --storage.local.retention {{ prometheus_tsdb_retention }} \
      {% endif -%}
      --log.level {{ prometheus_log_level }} \
      {{ prometheus_additional_cli_args }}
end script

respawn
respawn limit 10 10
kill timeout 10
